package org.yzh.web.mp.entity;

import cn.hutool.core.convert.Convert;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.time.LocalDateTime;
import java.time.ZoneId;

/**
 * @description: Alarm基础类
 * @author: nick
 * @date: 2024-06-19
 **/
@Data
public class AlarmBase {

    /**
     * 上传时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Long time;

    /**
     * 车辆id
     */
    private String vehicleId;

    /**
     * 报警/事件类型
     */
    private Integer eventType;

    /**
     * 报警等级
     */
    private Integer alarmLevel;

    /**
     * 报警Id(附件集合)
     */
    private String alarmId;

    /**
     * 附件数
     */
    private Integer attachments;

    /**
     * 经度
     */
    private String longitude;

    /**
     * 纬度
     */
    private String latitude;

    /**
     * 新增时间
     */
    private Long addTime;

    /**
     * tags
     */
    private String cid;


    public  <T extends AlarmBase> T populateAlarmFields(String vehicleId, Integer eventType,
                                                       Integer alarmLevel, Long alarmId,
                                                       Integer attachments, LocalDateTime time,
                                                       Double longitude, Double latitude,
                                                       T alarmBase) {
        alarmBase.setTime(time.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
        alarmBase.setVehicleId(vehicleId);
        alarmBase.setEventType(eventType);
        alarmBase.setAlarmLevel(alarmLevel);
        alarmBase.setAlarmId(Convert.toStr(alarmId));
        alarmBase.setAttachments(attachments);
        alarmBase.setLongitude(Convert.toStr(longitude));
        alarmBase.setLatitude(Convert.toStr(latitude));
        alarmBase.setAddTime(System.currentTimeMillis());
        alarmBase.setCid(vehicleId);
        return alarmBase;
    }


}
